#include <string>
#include <iostream>
#include <sstream>
#include "serializable.hpp"

class Consumer {
 public:
  virtual bool consume(std::string s) = 0;
};

class ConsumerA : public Consumer {
 public:
  ConsumerA() {
    prototype = new A(0);
  }
  ~ConsumerA() {
    delete prototype;
  }
  bool consume(std::string s) {
    A* object = (A*)(prototype->deserialize(s));
    if (object != NULL) {
      std::cout << "Data A:" << object->get_data() << std::endl;
      delete object;
      return true;
    }
    return false;
  }
 private:
  A* prototype;
};

class ConsumerB : public Consumer {
 public:
  ConsumerB() {
    prototype = new B(0);
  }
  ~ConsumerB() {
    delete prototype;
  }
  bool consume(std::string s) {
    B* object = (B*)(prototype->deserialize(s));
    if (object != NULL) {
      std::cout << "Data B:" << object->get_data() << std::endl;
      delete object;
      return true;
    }
    return false;
  }
 private:
  B* prototype;
};

class ConsumerC : public Consumer {
 public:
  ConsumerC() {
    prototype = new C(0);
  }
  ~ConsumerC() {
    delete prototype;
  }
  bool consume(std::string s) {
    C* object = (C*)(prototype->deserialize(s));
    if (object != NULL) {
      object->execute();
      delete object;
      return true;
    }
    return false;
  }
 private:
  C* prototype;
};
